home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / pascal / comprog.pas < prev    next >
Pascal/Delphi Source File  |  1991-10-01  |  5KB  |  199 lines

  1. program GenComProg;
  2. {$X+}
  3. {$R+}
  4. uses
  5.        dos, objects, drivers,
  6.        App, menus, views, dialogs,
  7.        AnsiView,
  8.        COMIo;
  9.  
  10. Const
  11.    cmBase         = 100;
  12.    cmNotYet       = cmBase;
  13.    cmAbout        = cmBase + 1;
  14.    cmDosShell     = cmBase + 2;
  15.    cmConnect      = cmBase + 3;
  16.    cmSerialIn     = cmBase + 4;
  17.  
  18. type
  19.       PGenComApp = ^TGenComApp;
  20.       TGenComApp  = object(TApplication)
  21.         constructor Init;
  22.         procedure   GetEvent(var Event: TEvent); virtual;
  23.         procedure   HandleEvent(var E : TEvent); virtual;
  24.         procedure   Idle; virtual;
  25.         procedure   InitStatusLine;  virtual;
  26.         procedure   InitMenuBar;     virtual;
  27.         end;
  28.  
  29.       PComWindow = ^TComWindow;
  30.       TComWindow = OBJECT(TANSIView)
  31.                      Count : BYTE;
  32.                      constructor Init;
  33.                      procedure HandleEvent(var Event : TEvent); virtual;
  34.                   END;
  35.  
  36.       Config_Record = record
  37.             PhoneNumber : String[30]; {Inputline}
  38.             ModemString : String[20]; {Inputline}
  39.             ModemBaud : Word;  {Radiobuttons}
  40.             ModemPort : Word;  {Radiobuttons}
  41.             DataSize : Word;  {Radiobuttons}
  42.             ParityOpt : Word;  {Radiobuttons}
  43.             Options : Word; {Checkbox}
  44.             end;
  45.  
  46. var
  47.       GenComApp: PGenComApp;
  48.  
  49. const
  50.       DataRec : Config_Record = (
  51.          PhoneNumber : '623-7122';
  52.          ModemString : 'AT&C1&D2';
  53.          ModemBaud : 2;
  54.          ModemPort : 1;
  55.          DataSize  : 0;
  56.          ParityOpt : 1;
  57.          Options   : 2);
  58.  
  59. constructor TGenComApp.Init;
  60.  var
  61.        BuffSize : word;
  62.        R: TRect;
  63.        L: TPoint;
  64.        S: PStream;
  65.  begin
  66.  if (DataRec.Options and 4) = 4 then
  67.       BuffSize := $4000 else BuffSize := $1000;
  68.  ComInit(BuffSize);
  69.  TApplication.Init;
  70.  end;
  71.  
  72. procedure TGenComApp.InitMenuBar;
  73.  var R : TRect;
  74.  begin
  75.  GetExtent (R);
  76.  R. B. Y := R. A. Y + 1;
  77.  MenuBar := NEW (PMenuBar,
  78.     Init (R,NewMenu (
  79.             NewItem ('~C~onnect', 'Alt-C', kbAltC, cmConnect, hcNoContext,
  80.             NewItem ('E~x~it', 'Alt-X', kbAltX, cmQuit, hcNoContext,
  81.             nil)))));
  82.  end;
  83.  
  84. procedure TGenComApp.InitStatusLine;
  85.  var R : TRect;
  86.  begin
  87.  GetExtent (R);
  88.  R. A. Y := R. B. Y - 1;
  89.  StatusLine := NEW (PStatusLine,Init (R,NewStatusDef (0, $FFFF,
  90.                     NewStatusKey ('~Alt-X~ Exit', kbAltX, cmQuit,
  91.                     NewStatusKey ('~Alt-F3~ Close', kbAltF3, cmClose,
  92.                     NewStatusKey ('~F10~ Menu', kbF10, cmMenu,
  93.                     NewStatusKey ('', kbCtrlF5, cmResize,
  94.                     nil)))), nil)));
  95.  end;
  96.  
  97. procedure TGenComApp.GetEvent(var Event: TEvent);
  98.  begin
  99.  TApplication.GetEvent(Event);
  100.  end;
  101.  
  102. procedure TGenComApp.HandleEvent(var E : TEvent);
  103.  procedure NewComWindow;
  104.   var
  105.         PPtr : PComWindow;
  106.   begin
  107.   PPtr := NEW(PComWindow,Init);
  108.   if PPtr <> NIL THEN DeskTop^.Insert(PPtr);
  109.   end;
  110.  
  111.  begin
  112.  TApplication.HandleEvent(E);
  113.  if E.What = evCommand then begin
  114.      case E.Command of
  115.          cmConnect   : NewComWindow;
  116.          else
  117.             exit;
  118.          end;
  119.      ClearEvent(E);
  120.      end;
  121.  end;
  122.  
  123. procedure TGenComApp.Idle;
  124.  var
  125.      Fluckers : byte;
  126.      Fake     : pointer absolute Fluckers;
  127.  begin
  128.  if ComIsOpen then
  129.     if ComAvail then begin
  130.        Fluckers := ComGet;
  131.        Message(TopView,evCommand,cmSerialIn,Fake);
  132.        end;
  133.  
  134.  TApplication.Idle;
  135.  end;
  136.  
  137. constructor TComWindow.Init;
  138.  const
  139.   BaudArr: array[0..4] of Byte = (Baud300, Baud1200, Baud2400, Baud4800, Baud9600);
  140.   DataBitsArr: array[0..1] of Byte = (WordSize7, WordSize8);
  141.   ParityArr: array[0..2] of Byte = (NoParity, EvenParity, OddParity);
  142.  var
  143.       R : TRect;
  144.       L : TPoint;
  145.       X : BYTE;
  146.       Y : BYTE;
  147.  begin
  148.  R.Assign(1,2,73,12);
  149.  L.X := 80;
  150.  L.Y := 50;
  151.  TANSIView.Init(R,L,'Communications Window',0);
  152.  Options := Options or ofCentered;
  153.  with DataRec do
  154.     ComSetParam(ModemPort,
  155.                 BaudArr[ModemBaud] or
  156.                 DataBitsArr[DataSize] or
  157.                 ParityArr[ParityOpt] or
  158.                 StopBits1);
  159.  Count := 0;
  160.  GotoXY(1,1);
  161.  end;
  162.  
  163. PROCEDURE TComWindow.HandleEvent;
  164.  VAR   i : INTEGER;
  165.  BEGIN
  166.  TANSIView.HandleEvent(Event);
  167.  CASE Event.What OF
  168.       evKeyDown : begin
  169.                   if Event.CharCode <> #0 then
  170.                       if Event.CharCode = #13 then ComPut(13)
  171.                       else ComPut(Byte(Event.CharCode))
  172.                   else exit;
  173.                   end;
  174.       evCommand : if Event.Command = cmSerialIn then
  175.                     printchar(char(Event.InfoPtr))
  176.                     else exit;
  177.       ELSE EXIT
  178.  END;
  179.  ClearEvent(Event)
  180.  END;
  181.  
  182. begin
  183. with DataRec do begin
  184.    PhoneNumber := '623-7122';
  185.    ModemString := 'AT&C1&D2';
  186.    ModemPort := 1;
  187.    ModemBaud := 2;
  188.    DataSize  := 0;
  189.    ParityOpt := 1;
  190.    Options   := 2;
  191.    end;
  192.  
  193. GenComApp := New(PGenComApp,Init);
  194. GenComApp^.Run;
  195. Dispose(GenComApp,Done);
  196. ComDone;
  197.  
  198. end.
  199.